﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

/*
 * Author:Conis
 * Date:
 * Description:数据实体的基类
 */
namespace Conis.Squirrel.SqlBuilder
{
    /// <summary>
    /// 数据实体的基类，一个数据实体对应一张表
    /// </summary>
    public abstract class BaseConcrete
    {
        /// <summary>
        /// 数据存储的容器
        /// </summary>
        public Hashtable Container { get; protected set; }
        /// <summary>
        /// 表的名称
        /// </summary>
        public string TableName { get; protected set; }
        /// <summary>
        /// 主键的字段名
        /// </summary>
        public string PrimaryKey { get; protected set; }

        /// <summary>
        /// 数据实体的基类
        /// </summary>
        public BaseConcrete()
        {
            this.Container = new Hashtable();
        }

        /// <summary>
        /// 将数据行转换为数据实体
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public virtual BaseConcrete FromDataRow(DataRow row)
        {
            foreach (DataColumn col in row.Table.Columns)
            {
                object value = null;
                if (!row.IsNull(col))
                {
                    value = row[col];
                }
                this.Container[col.ColumnName] = value;
            }
            return this;
        }

    }
}
